<template>
    <div>
        <div class="fans-impor">
			<van-image
			  width="100%"
			  height="100%"
			  :src="Url+img"
			/>
            <!-- <img :src="Url+img" style="width: 100%; display: block;"   @touchstart.prevent="qrcodeimgStart()" @touchend.prevent="qrcodeimgEnd()"  ref="qrcode"> -->
            <p class="red_ft">保存上方图片，发送给客户，客户扫码后即可成为你的粉丝，并且能接收你的消息推送~</p>
		</div>
    </div>
</template>

<script>
    import QrCode from 'qrcode-decoder';
    export default {
        name: "",
        data(){
            return{
                img:""
            }
        },
        mounted(){
            this.getImg();
        },
        methods:{
            //  长按识别二维码 开始
            qrcodeimgStart:function () {
                var that=this;
                clearTimeout(this.Loop); //再次清空定时器，防止重复注册定时器
                this.Loop = setTimeout(function() {
                    that.$dialog.confirm({
                        message: '识别图中二维码',
                    }).then(() => {
                        // on confirm
                        var qr = new QrCode();

                        let img = this.$refs['qrcode']
                        console.log(img);
                        qr.decodeFromImage(img,{
                            crossOrigin: "anonymous"
                        }).then((res) => {
                            console.log(res.data);
                            var ress=res.data;
                            var url = that.Url + 'api' + ress.match(/api(\S*)/)[1];
                            location.href=url;
                        });
                    })
                        .catch(() => {
                            // on cancel
                        });

                }.bind(this), 1000);
            },
            //  长按识别二维码 结束
            qrcodeimgEnd(){
                clearTimeout(this.Loop);
            },
            getImg(){
                var that=this;

                that.request1.post1({
                    url: that.Url + "api/user.index/daofensucai",
                    params: { },
                    success: function (res) {
                        console.log(res)
                        if (res.data.code == 1) {
                            that.img=res.data.data.daofenerweima;
                        } else {
                            alert(res.data.msg)
                        }
                    },
                    fail: function (error) {
                        alert(error.data.msg)
                    }
                })
            }
        }
    }
</script>

<style scoped>
    .fans-impor .red_ft {
        line-height: 24px;
        font-size: 14px;
        display: block;
        background: #fffbba;
        font-weight: 700;
        margin: 20px auto 0;
        width: 80%;
        border-radius: 8px;
        padding: 10px 5%;
    }
</style>